package com.i8office.android.zhihuixinwu.module.model;

import com.cyan.tools.callback.RequestCallback;
import com.i8office.android.zhihuixinwu.app.App;
import com.i8office.android.zhihuixinwu.bean.OpinionInfo;
import com.i8office.android.zhihuixinwu.bean.Result;
import com.i8office.android.zhihuixinwu.module.contract.OpinionContract;
import com.i8office.android.zhihuixinwu.util.OfficeSubscriber;

import java.util.ArrayList;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by pc on 2018/7/7.
 */

public class OpinionModel implements OpinionContract.Model {
    @Override
    public Disposable getPublicOpinion(final RequestCallback<ArrayList<String>> callback) {
        return App.getComponent().getAPIService().getPublicOpinion().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Result<OpinionInfo>>(callback) {
            @Override
            public void onNext(Result<OpinionInfo> o) {
                callback.requestSuccess(o.getData().getOpinions());
            }
        });
    }

    @Override
    public Disposable getPrivateOpinion(final RequestCallback<ArrayList<String>> callback) {
        return App.getComponent().getAPIService().getPrivateOpinion().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Result<OpinionInfo>>(callback) {
            @Override
            public void onNext(Result<OpinionInfo> o) {
                callback.requestSuccess(o.getData().getOpinions());
            }
        });
    }
}
